//
//  AppString.h
//  Demo_String
//
//  Created by apple on 2020/3/9.
//  Copyright © 2020 apple. All rights reserved.
//

// 没有开启优化的情况下gcc默认不展开 inline 函数，简单的讲就是不优化的情况下，inline 没有任何作用。
#ifndef AppString_h
#define AppString_h

#ifndef DecodeCString
#define DecodeCString   _5C276904_F31_B643CA_7A2_4E6C4F369CC4
#endif

#ifndef DecodeOcString
#define DecodeOcString  _897DE2E4_175_F0C445_203_29549CFFE480
#endif

#ifdef __cplusplus
extern "C" {
#endif

typedef struct _EncodedString {
    char* origstr;
    int size;
}EncodedString;
// 解密C字符串
static inline char * DecodeCString(EncodedString *str) {
    
    char seed = str->origstr[str->size-1];
    
    int j = 0;
    
    do {
        str->origstr[j] ^= seed;
        j++;
    } while (j < str->size);
    
    return str->origstr;
}

#ifdef __OBJC__
#import <Foundation/Foundation.h>
// 解密OC字符串
static inline NSString * DecodeOcString(EncodedString *str) {
    
    char seed = str->origstr[str->size-1];
    
    int j = 0;
    
    do {
        str->origstr[j] ^= seed;
        j++;
    } while (j < str->size);
    
    return [[NSString alloc] initWithBytesNoCopy:str->origstr length:str->size-1 encoding:NSUTF8StringEncoding freeWhenDone:0];
}
#endif

#ifdef __cplusplus
}
#endif


#endif /* AppString_h */
